import store from "../../store/store";
import $ from "jquery";
import {url} from "../../util/config";
import {success} from "../../util/responseStatus";
import {message} from "antd";
import login from "../login";
/**
 *
 * @param moduleId
 * @returns {[
 * moduleId : null,
 * moduleType : "file或者article",
 * moduleName : null
 * ]}
 */
function getNewLogin(moduleId) {
    return getModuleDetail(moduleId)
}
export default function getModuleDetail(moduleId) {
    let moduleDetail = null;
    //之前是根据store的status状态值来判断是否更新，因为那是前端自己需要做刷新，现在刷新交给后端完成
    // if(store.getState().status){
    //    走ajax
    let token = localStorage.getItem("token")
    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        url: url.api_url+`Module/getModuleDetail?moduleId=${moduleId}`,
        type: 'get',
        success: function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                moduleDetail = getNewLogin(moduleId)
            }else {
                moduleDetail = result.result
            }
        },
        error:function (error) {
            message.error("请求异常")
        }
    })
    return moduleDetail;
}
